🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / model / src / commonMain / kotlin / org / meshtastic / core / model / ConnectionState.kt
Displaying Raw • Download
core/model/src/commonMain/kotlin/org/meshtastic/core/model/ConnectionState.kt bd2863243bab6eb213401d949839a2bc74dde7e2 (bd286324) Text, 3.67 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.model
Tff7b72sealed Tff7b72interface T56d364ConnectionState Tb4b4b4{
T8b949e/** We are disconnected from the device, and we should be trying to reconnect. */
Tff7b72data Tff7b72object T56d364Disconnected Tb4b4b4: Te6edf3ConnectionState
T8b949e/** We are currently attempting to connect to the device. */
Tff7b72data Tff7b72object T56d364Connecting Tb4b4b4: Te6edf3ConnectionState
T8b949e/** We are connected to the device and communicating normally. */
Tff7b72data Tff7b72object T56d364Connected Tb4b4b4: Te6edf3ConnectionState
T8b949e/** The device is in a light sleep state, and we are waiting for it to wake up and reconnect to us. */
Tff7b72data Tff7b72object T56d364DeviceSleep Tb4b4b4: Te6edf3ConnectionState
Tb4b4b4}
T8b949e/**
* One atomically published view of canonical connection state and its lifecycle evidence.
*
* Consumers that need to correlate a state with departure or handshake counters must observe this snapshot instead of
* reading [ConnectionState] and [ConnectionEpochs] flows independently.
*/
Tff7b72data Tff7b72class T56d364ConnectionLifecycleTb4b4b4(
T8b949e/**
* Monotonically increasing identity of this snapshot. Consumers capture it before a long operation and reject the
* result if the current value differs.
*/
Tff7b72val Te6edf3versionTb4b4b4: Tffa657Long Tff7b72= T79c0ff0Tb4b4b4,
Tff7b72val Te6edf3stateTb4b4b4: Te6edf3ConnectionState Tff7b72= Te6edf3ConnectionStateTb4b4b4.Te6edf3DisconnectedTb4b4b4,
Tff7b72val Te6edf3epochsTb4b4b4: Te6edf3ConnectionEpochs Tff7b72= Te6edf3ConnectionEpochsTb4b4b4(Tb4b4b4)Tb4b4b4,
Tb4b4b4)
T8b949e/**
* Monotonic counters for connection lifecycle events that cannot be inferred reliably from transient [ConnectionState]
* values. A fast disconnect/reconnect may be observed only as the final state, while these counters retain both
* lifecycle boundaries.
*
* @property departures Number of transitions away from [ConnectionState.Connected].
* @property completedHandshakes Number of transitions into [ConnectionState.Connected].
* @property handshakesAtLastDeparture Completed-handshake count captured at the most recent departure. This preserves
* event ordering when a fast departure/reconnect pair is conflated into one observed state-flow value.
* @property lastDepartureState State entered by the most recent departure. Consumers that react after a fast reconnect
* can use this event evidence instead of rereading the already-advanced live connection state.
*/
Tff7b72data Tff7b72class T56d364ConnectionEpochsTb4b4b4(
Tff7b72val Te6edf3departuresTb4b4b4: Tffa657Long Tff7b72= T79c0ff0Tb4b4b4,
Tff7b72val Te6edf3completedHandshakesTb4b4b4: Tffa657Long Tff7b72= T79c0ff0Tb4b4b4,
Tff7b72val Te6edf3handshakesAtLastDepartureTb4b4b4: Tffa657Long Tff7b72= T79c0ff0Tb4b4b4,
Tff7b72val Te6edf3lastDepartureStateTb4b4b4: Te6edf3ConnectionState? Tff7b72= Tff7b72nullTb4b4b4,
Tb4b4b4) Tb4b4b4{
T8b949e/** Returns the counters after applying one canonical connection-state transition. */
Tff7b72fun Td2a8ffadvanceTb4b4b4(Te6edf3previousTb4b4b4: Te6edf3ConnectionStateTb4b4b4, Te6edf3currentTb4b4b4: Te6edf3ConnectionStateTb4b4b4)Tb4b4b4: Te6edf3ConnectionEpochs Tff7b72= Tff7b72when Tb4b4b4{
Te6edf3previous Tff7b72is Te6edf3ConnectionStateTb4b4b4.Te6edf3Connected Tff7b72&Tff7b72& Te6edf3current Tff7b72!is Te6edf3ConnectionStateTb4b4b4.Te6edf3Connected Tff7b72-Tff7b72>
Te6edf3copyTb4b4b4(
Te6edf3departures Tff7b72= Te6edf3departures Tff7b72+ T79c0ff1Tb4b4b4,
Te6edf3handshakesAtLastDeparture Tff7b72= Te6edf3completedHandshakesTb4b4b4,
Te6edf3lastDepartureState Tff7b72= Te6edf3currentTb4b4b4,
Tb4b4b4)
Te6edf3previous Tff7b72!is Te6edf3ConnectionStateTb4b4b4.Te6edf3Connected Tff7b72&Tff7b72& Te6edf3current Tff7b72is Te6edf3ConnectionStateTb4b4b4.Te6edf3Connected Tff7b72-Tff7b72>
Te6edf3copyTb4b4b4(Te6edf3completedHandshakes Tff7b72= Te6edf3completedHandshakes Tff7b72+ T79c0ff1Tb4b4b4)
Tff7b72else Tff7b72-Tff7b72> Tff7b72this
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.05s